app.controller("carController",function($scope,carService,orderService){
	
	$scope.loadCarDatas=function(){
		carService.loadDatas().then(function success(response){
			console.log(response);
			$scope.flag = response.data.status;
			if(response.data.status==="success"){
				$scope.cars = response.data.data;
			}
		})
	}
	$scope.deleteGoodsById=function(pid,total,totals){
		carService.deleteDatas(pid).then(function success(response){
			console.log(response);
			$scope.flag=response.data.status;
			if(response.data.status==="success"){
				$scope.cars=response.data.data;
			}
		});
	}
	$scope.modifyGoodsQty=function(pid,$event){
		carService.modifyGoodsQty(pid,$event.target.value).then(function success(response){
			console.log(response);
			$scope.flag = response.data.status;
			if(response.data.data==="success"){
				$scope.cars=response.data.message;
			}
		});
	}
	$scope.saveOrder=function(){
		orderService.saveOrder().then(function success(response){
			console.log(response);
			if(response.data.status==="false"){
				location.href="2login.html";
			}else{
				if(response.data.data.indexOf("oid")==0){
					location.href="6订单.html#?"+response.data.data;
				}
			}
		});
	}
	$scope.deleteAllGoods=function(){
		$scope.flag=false;
		carService.deleteAllGoods().then(function success(response){
			console.log(response);
			if(response.data.data==="success"){
				$scope.cars=response.data.message;
			}
		});
	}
});